jj: derive author/committer from git config, not just directory path - #24
Merged
Conversation
…oping jj's own config format only supports path/hostname/command-based conditions (--when.repositories etc.) — no remote-URL condition like git's hasconfig:remote.*.url:. Since colocated repos already resolve the right identity through git's conditional includes, wrap jj in a zsh function that reads git config user.name/user.email and passes them through as --config overrides, so jj mirrors git's remote-based detection instead of relying on where the repo happens to be cloned.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces a jj wrapper function in the Home Manager Zsh configuration so that, when invoked inside a Git work tree, it derives user.name / user.email from git config and passes them into jj via --config overrides. This aligns JJ’s identity resolution with Git’s existing per-repo identity logic (including remote-URL-based hasconfig: setups), ensuring both Author and Committer are consistently correct on every operation.
Changes:
- Add a Zsh
jjfunction that detects when it’s running inside a Git work tree. - Read
git config user.email/user.nameand inject them into JJ via--configoverrides. - Fall back to the real
jjbinary (and JJ’s own config) when not inside a Git repo or when Git identity is unavailable.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+46
to
+52
| local email name | ||
| email=$(git config user.email 2>/dev/null) | ||
| name=$(git config user.name 2>/dev/null) | ||
| if [[ -n "$email" && -n "$name" ]]; then | ||
| command jj --config "user.email=\"$email\"" --config "user.name=\"$name\"" "$@" | ||
| return | ||
| fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
jj's own config format (checked against the installed 0.43.0's bundled docs,
jj help -k config) only supports conditional overrides on repo/workspace path, hostname, or subcommand — there's no equivalent of git's remote-URL-basedhasconfig:remote.*.url:*...*condition used in bedag-setup'sgitconfig.nix. The path-based--when.repositoriesscope added in #21 only fixes identity for repos cloned under~/git/bedag*, and — as surfaced live — doesn't retroactively refresh the committer field on already-created commits, which is what GitLab's push hook actually checks.This adds a
jjzsh function (modules/shell.nix) that shadows the real binary: for any invocation inside a git work tree, it readsgit config user.email/user.name(which already resolves correctly per-repo via the existinghasconfig:include) and passes them through asjj --configoverrides. That gives jj the same remote-based detection git already has, for both author and committer, on every operation — not just a static path guess. Falls back to jj's own config (including the path-based scope from #21, kept as a fallback for non-colocated jj repos) when not inside a git repo.Verified in a scratch colocated repo: with the wrapper applied consistently (including to
jj git init), bothAuthorandCommittercame out correctly from git's resolved identity; a partial test (only wrappingdescribe, notgit init) reproduced the exact stale-author symptom seen live, confirming the mechanism.Test plan
nix-instantiate --parseonmodules/shell.nixgit init/describe/showall report the git-resolved identity for both Author and Committerhome-manager switch, open a new shell, runjj showinside~/git/bedag/observability-deploymentand confirm Author/Committer both show the bedag identity without relying on the path scope